package com.example.myapplication

import com.example.myapplication.clean_craftsmanship.Bowling
import org.junit.Test

/**
 *搭梯测试：一步步增加难度到合适的层级
 **/
class BowlingTest {
    private val bowling = Bowling()

    @Test
    fun createBowling() {
        val bowling = Bowling()
    }

    @Test
    fun roll() {
        println(bowling.oneRoll())
    }

    @Test
    fun getFirstRollScore() {
        println(bowling.oneRoll())
        println(bowling.oneRoll())
        println(bowling.firstRoll)
    }

    @Test
    fun getSecondRollScore() {
        println(bowling.oneRoll())
        println(bowling.oneRoll())

        println(bowling.secondRoll)
    }

    @Test
    fun threeRollAndGetFirstRollScore() {
        println(bowling.oneRoll())
        println(bowling.oneRoll())
        println(bowling.oneRoll())

        println(bowling.firstRoll)
    }

    @Test
    fun threeRollAndGetSecondRollScore() {
        println(bowling.oneRoll())
        println(bowling.oneRoll())
        println(bowling.oneRoll())

        println(bowling.secondRoll)
    }


    ///////////////////////////////////////////////////////////////////////////
// 测试局数分数
///////////////////////////////////////////////////////////////////////////


    @Test
    fun getFirstRoundScore_throw() {
        bowling.getScore(1)
    }

    @Test
    fun reset() {
        bowling.oneRoll()
        bowling.reset()
        println(bowling.getScore())
    }


    @Test
    fun oneRollAndGetFirstRoundScore() {
        println(bowling.testRoll(9))
        println(bowling.getScore(1))
    }

    @Test
    fun threeRollAndGetFirstRoundScore() {
        println(bowling.testRoll(5))
        println(bowling.testRoll(1))
        println(bowling.testRoll(2))
        //correct result:6
        println(bowling.getScore(1))
    }

    @Test
    fun threeRollAndGetSecondRoundScore() {
        println(bowling.testRoll(5))
        println(bowling.testRoll(1))
        println(bowling.testRoll(2))
        //correct result:2
        println(bowling.getScore(2))
    }

    // TODO: Strike 测试
    @Test
    fun threeRollStrikeAndGetRoundScore() {
        println(bowling.testRoll(10))
        println(bowling.testRoll(1))
        println(bowling.testRoll(2))
        //correct result: 13、3
        println(bowling.getScore(1))
        println(bowling.getScore(2))
    }

    @Test
    fun fourRollStrikeAndGetRoundScore() {
        println(bowling.testRoll(10))

        println(bowling.testRoll(1))
        println(bowling.testRoll(2))

        println(bowling.testRoll(3))
        //correct result: 13、3、3
        println(bowling.getScore(1))
        println(bowling.getScore(2))
        println(bowling.getScore(3))
    }

    @Test
    fun fourRollTwoStrikeAndGetRoundScore() {
        println(bowling.testRoll(10))

        println(bowling.testRoll(10))

        println(bowling.testRoll(2))
        println(bowling.testRoll(3))
        //correct result: 20、15、5
        println(bowling.getScore(1))
        println(bowling.getScore(2))
        println(bowling.getScore(3))
    }

    @Test
    fun sixRollTwoStrikeAndGetRoundScore() {
        println(bowling.testRoll(10))

        println(bowling.testRoll(2))
        println(bowling.testRoll(3))

        println(bowling.testRoll(10))

        println(bowling.testRoll(4))
        println(bowling.testRoll(5))
        //correct result: 15、5、19、9
        println(bowling.getScore(1))
        println(bowling.getScore(2))
        println(bowling.getScore(3))
        println(bowling.getScore(4))
    }

    // TODO: Spare测试
    @Test
    fun fourRollSpareAndGetRoundScore() {
        println(bowling.testRoll(4))
        println(bowling.testRoll(6))

        println(bowling.testRoll(2))
        println(bowling.testRoll(3))
        //correct result: 12、5
        println(bowling.getScore(1))
        println(bowling.getScore(2))
    }

    @Test
    fun sixRollSpareAndGetRoundScore() {
        println(bowling.testRoll(4))
        println(bowling.testRoll(6))

        println(bowling.testRoll(2))
        println(bowling.testRoll(3))

        println(bowling.testRoll(4))
        println(bowling.testRoll(5))
        //correct result: 12、5、9
        println(bowling.getScore(1))
        println(bowling.getScore(2))
        println(bowling.getScore(3))
    }

    @Test
    fun sixRollTwoSpareAndGetRoundScore() {
        println(bowling.testRoll(4))
        println(bowling.testRoll(6))

        println(bowling.testRoll(8))
        println(bowling.testRoll(2))

        println(bowling.testRoll(4))
        println(bowling.testRoll(5))
        //correct result: 18、14、9
        println(bowling.getScore(1))
        println(bowling.getScore(2))
        println(bowling.getScore(3))
    }

    @Test
    fun sevenRollTwoSpareAndGetRoundScore() {
        println(bowling.testRoll(4))
        println(bowling.testRoll(6))

        println(bowling.testRoll(2))
        println(bowling.testRoll(2))

        println(bowling.testRoll(4))
        println(bowling.testRoll(6))

        println(bowling.testRoll(6))
        //correct result: 12、4、16、6
        println(bowling.getScore(1))
        println(bowling.getScore(2))
        println(bowling.getScore(3))
        println(bowling.getScore(4))
    }

    // TODO: Spare And Strike Test
    @Test
    fun sevenRollSpareAndStrikeAndGetRoundScore() {
        println(bowling.testRoll(4))
        println(bowling.testRoll(6))

        println(bowling.testRoll(10))

        println(bowling.testRoll(6))
        println(bowling.testRoll(4))

        println(bowling.testRoll(6))
        println(bowling.testRoll(2))
        //correct result: 20、20、16、8
        println(bowling.getScore(1))
        println(bowling.getScore(2))
        println(bowling.getScore(3))
        println(bowling.getScore(4))
    }

    @Test
    fun getScore() {
        sevenRollSpareAndStrikeAndGetRoundScore()
        //correct result:64
        println(bowling.getScore())
    }

    @Test
    fun allRoll() {
        bowling.allRoll()
        println(bowling.getScore())
    }

    @Test
    fun perfectGame() {
        bowling.perfectGame()
        println(bowling.getScore())
    }


}